//用户出的
var stbmsg;
$(function () {

    var userch;//0:布；1：剪刀；2：石头
    function userchu(n, w) {
        switch (n) {
            case 0:
                var img = '/img/bu.png';
                break;
            case 1:
                var img = '/img/jd.png';
                break;
            case 2:
                var img = '/img/cz.png';
                break;
        }
        if (w == 'u') {
            $('#usershow').css('background', 'url(' + img + ')');
            userch = n;
        } else {
            $('#ai').css('background', 'url(' + img + ')');
        }
    }

//执行函数


    function zhixing(n) {
        userchu(n, 'u');
        //动画
        $('#usershow').animate({
            bottom: '90px',
        }, 500).show(500);
        //ajax获取数据
        $.ajax({
            type: 'post',
            url: '/back/game.php?type=stb',
            data: {'userch': n, 'yaya': $('#num').val()},
            //async:false,
            success: function (msg) {
                if (msg == 0) {
                    alert('数据异常');
                } else {
                    stbmsg = JSON.parse(msg);
                    setTimeout("Dialog.init(stbmsg.xiaoxi,2000);$('#ji_fen').val(stbmsg.jifen);$('#add').click(addnum);$('#jian').click(jiannum);",2500);
                    userchu(stbmsg.num, 'a');
                    //动画
                    $('#ai').animate({
                        top: '20px',
                    }, 500).show(500);
                    //动画回去
                    setTimeout(function () {
                        $('#usershow').animate({
                            bottom: '-239px',
                        }, 500).hide(500);
                        $('#ai').animate({
                            top: '-239px',
                        }, 500).hide(500);
                    }, 3000);
                }
            }
        });
    }

//三个选项
    $('#jiandao').click(function () {
        var can = cango();
        if (can) {
            if (jdaoTime != 'aa') {
                return false;
            }
            jdaoTime = setInterval(function () {
                tt--;
                if (tt < 0) {
                    clearInterval(jdaoTime);
                    jdaoTime = 'aa';
                    tt = 3;
                }
            }, 1000);
            $('#add').off();
            $('#jian').off();
            mc();
            zhixing(1);
        }
    });
    $('#shitou').click(function () {
        var can = cango();
        if (can) {
            if (jdaoTime != 'aa') {
                return false;
            }
            jdaoTime = setInterval(function () {
                tt--;
                if (tt < 0) {
                    clearInterval(jdaoTime);
                    jdaoTime = 'aa';
                    tt = 3;
                }
            }, 1000);
            $('#add').off();
            $('#jian').off();
            mc();
            zhixing(2);
        }
    });
    $('#bu').click(function () {
        var can = cango();
        if (can) {
            if (jdaoTime != 'aa') {
                return false;
            }
            jdaoTime = setInterval(function () {
                tt--;
                if (tt < 0) {
                    clearInterval(jdaoTime);
                    jdaoTime = 'aa';
                    tt = 3;
                }
            }, 1000);
            $('#add').off();
            $('#jian').off();
            mc();
            zhixing(0);
        }
    });
});
